package com.wang.userscenter.common.util;

import java.io.InputStream;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;

/**
 * 存储一些常量
 */
public class ConstatFinalUtil {
	public static final IoUtil IO_UTIL = new IoUtil();
	/**
	 * 存储常量;纯数字
	 */
	public static final String ALLSTR_NUM = "23456789";
	/**
	 * 纯字母
	 */
	public static final String ALLSTR_CHAR = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ";
	/**
	 * 纯字母+数字
	 */
	public static final String ALLSTR_CHAR_NUM = ALLSTR_NUM + ALLSTR_CHAR;
	
	/**
	 * 配置文件中的信息
	 */
	public static JSONObject CONFIG_JSON = new JSONObject();
	/**
	 * 提示信息的json,从configJSON中获取
	 */
	public static JSONObject INFO_JSON = new JSONObject();
	/**
	 * 提示信息的json,从configJSON中获取
	 */
	public static JSONObject SYS_CONFIG_JSON = new JSONObject();
	
	/**
	 * 定义常量
	 */
	public static final String INFO_STR_CODE = "code";
	public static final String INFO_STR_INFO = "info";
	public static final String INFO_STR_DATA = "data";
	public static final String INFO_STR_EFFECT = "effect";
	public static final String INFO_STR_ID = "id";
	public static final String INFO_STR_SUCCESS = "0";
	public static final String INFO_STR_FAILED = "1";
	public static final String INFO_STR_EMAIL_EXISTS = "2";
	public static final String INFO_STR_PARAM_ERROR = "3";
	public static final String INFO_ILLEG_LOGIN = "illegLogin";
	/* 读取配置文件的信息(json) */
	public static final String INFO_SYS_CONFIG = "sys_config";
	public static final String INFO_ALL_RIGHT_CODE = "all_right_code";
	public static final String INFO_TRUEPATH = "truePath";
	public static final String INFO_RELAPATH = "relaPath";
	
	/**
	 * 静态代码块
	 */
	static {
		/* 
		 * 思路:
		 * 1:读取config.json中的文件内容(注意它是一个json格式的字符串)
		 * 2:把字符串变成json对象即可
		 * 
		 * 从classpath中获取文件的流;编译后的class文件存储的位置
		 *  */
		InputStream is = ConstatFinalUtil.class.getClassLoader().getResourceAsStream("config.json");
		/* io:读取文件内容(字符流) */
		String configJsonStr = IO_UTIL.readContent(is);
		CONFIG_JSON = JSON.parseObject(configJsonStr);
		/* 提示信息 */
		INFO_JSON = CONFIG_JSON.getJSONObject("info");
		SYS_CONFIG_JSON = CONFIG_JSON.getJSONObject(INFO_SYS_CONFIG);
	}
	
	public static void main(String[] args) {
		System.out.println("====" + CONFIG_JSON);
		System.out.println("====" + INFO_JSON);
	}
}
